How to Stay on Same Page

您所在的位置:网站首页 on same page How to Stay on Same Page

How to Stay on Same Page

2022-12-26 01:09| 来源: 网络整理| 查看: 265

Just a clarification of what's going on . . .

When you do this

More HTML

This is a valid (though not all that efficient) use of PHP. But when you attempt to use header(), you will always get that error because the very first line above - "" is page output. The server sends a content type header. So when you try to print a location header, it's too late, "headers already sent."

As for this,

I think its saying, "IF there is an email address, then say something like, 'email already subscribed?' else add it?"

Close. When you post a form, it posts data to the server. That data, for form method="post", is present in the PHP $_POST variable. So what it's saying is "if someone has posted this form, 'do something', otherwise display the form."

"Add it" is another whole topic. You have to cleanse the data, and also check to see if it already exists in the database, THEN add it. All that goes inside the first "if," but to be useful, we'd need to change our logic a little. If there's an error, we'd want to display the form.

So what happens here:

- if the form hasn't been submitted, it displays the form. - if someone submits the form, -- Check the data. If errors, --- display form with errors -- if no errors, --- Store the data in the database --- Display confirmation message

There are a million and a half ways to do this, this is not the "best" solution but don't want to lose you in the details. :-)



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3